const axios = require('axios')
const schedule = require('node-schedule');
const moment = require('moment');
const fs = require('fs');
const {log,pusher1,pusher2,pusher3,sendDing} = require("./util.js");
const CONFIG=JSON.parse(fs.readFileSync('./config.json'));
// fs.writeFileSync('./config.json', JSON.stringify(config));

function getDouban(){
    axios.get('https://movie.douban.com/j/search_subjects?type=tv&tag=%E7%83%AD%E9%97%A8&page_limit=50&page_start=0')
    .then((response) => {
        console.log('success')
        log(response.data,'douban')
    })
    .catch((error) => {
        console.log('error')
    });
}

function getIciba(){
    var config = {
        method: 'get',
        url: 'http://open.iciba.com/dsapi/',
        headers: { 
          'Pragma': 'no-cache', 
          'Accept-Encoding': 'gzip, deflate', 
          'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', 
          'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', 
          'Accept': '*/*', 
          'Referer': 'http://demo1.zhengoma.cn/', 
          'Connection': 'keep-alive', 
          'Cache-Control': 'no-cache'
        }
      };
      
      axios(config)
      .then(function (response) {
        let data = response.data;
        // data.content 英文
        // data.note 中文
        // data.fenxiang_img 分享图
		pusher2(data.note)

      })
      .catch(function (error) {
        log(error,'iciba')
      });
}





function scheduleCancel(){
	console.log('定时器开启……');
    var counter = 1;
    const j = schedule.scheduleJob('1 1 * * * *', function(timez){ // 秒、分、时、日、月、周几
	//timez 2021-01-05T03:05:01.000Z  
        let timeStr = timez.toString();
        console.log(timeStr)
		if(timeStr.includes('09:01:01')){
			getIciba();
		}
		if(timeStr.includes('22:01:01')){
			 
		}
		if(timeStr.includes('08:01:01')){
			 
		}
		// if(timeStr.includes('12:32:01')){
			// pusher3('ssss3')
		// }
		// if(timeStr.includes('12:33:01')){
			// sendDing('sendDing')
		// }
		
        // if(counter>5){
            // console.log('定时器取消')
            // // 定时器取消
            // j.cancel();  
        // }else{
			
        // }
        // console.log('定时器触发次数：' + counter);
        // counter++;
        
    });
}

function today31(){
    var config = {
        method: 'get',
        url: 'http://api.h-camel.com/api?mod=interview&ctr=issues&act=today',
    };

    axios(config)
    .then(function (response) {
        if(response.data.result.dToday===moment().format('YYYY.MM.DD')){
            let str = '\n'+response.data.result.today.map(i=>`【${i.label}】${i.title}\n${i.body}`).join('\n\n')
            console.log(str);
            sendDing(str)
        }
        
    })
    .catch(function (error) {
        console.log(error);
    });
}

// scheduleCancel();
today31();